package com.esp.app.bluetooth;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;

import com.esp.app.widget.MyWidgetProvider;
import com.esp.app.widget.R;
import com.esp.app.wifi.ViewHandler;

public class ViewBlueHandler {
	
	private static final String TAG = ViewHandler.class.getName();

	public static void updateAppWidgets(final Context context,
			final AppWidgetManager appWidgetManager, final int[] appWidgetIds,
			final int resource) {

		Log.d(TAG, " ViewBlueHandler|=> updateAppWidgets() ");

		for (int i = 0; i < appWidgetIds.length; i++) {
			final int appWidgetId = appWidgetIds[i];
			updateAppWidget(context, appWidgetManager, appWidgetId, resource);
		}

	}

	public static void updateAppWidget(final Context context,
			final AppWidgetManager appWidgetManager, final int appWidgetId,
			final int resource) {

		Log.d(TAG, " ViewBlueHandler|=> updateAppWidget() ");

		final RemoteViews views = new RemoteViews(context.getPackageName(),
				R.layout.widget_layout);
		views.setImageViewResource(R.id.btn_bluetooth,resource);
		
		final PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
				0, new Intent(MyWidgetProvider.TOGGLE_BLUETOOTH_STATE),
				PendingIntent.FLAG_UPDATE_CURRENT);
		views.setOnClickPendingIntent(R.id.btn_bluetooth, pendingIntent);
		appWidgetManager.updateAppWidget(appWidgetId, views);

	}
	  
}
